package hah;

public class longestCommonPrefix {
    public String longestCommonPrefix(String[] strs){
        if (strs.equals(" ")||strs.length==0){
            return " ";
        }
        int strs0Length=strs[0].length();
        int strsLength=strs.length;
        for (int i=0;i<strs0Length;i++){
            char c=strs[0].toCharArray()[i];
            for (int j=1;j<strsLength;j++){
                if (i==strs[j].length()||strs[j].toCharArray()[i]!=c){
                    return strs[0].substring(0,i);
                }
            }
        }
        return strs[0];
    }
}
